{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   0  1\n",
      "0  0  5\n",
      "1  1  6\n",
      "2  2  7\n",
      "3  3  8\n",
      "4  4  9\n"
     ]
    }
   ],
   "source": [
    "# 将长度相等的Series组合成DataFrame\n",
    "\n",
    "# 方法1\n",
    "c1 = pd.Series(range(0, 5))\n",
    "c2 = pd.Series(range(5, 10))\n",
    "df = pd.concat([c1, c2], axis=1)\n",
    "print(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   column1  1\n",
      "0        0  5\n",
      "1        1  6\n",
      "2        2  7\n",
      "3        3  8\n",
      "4        4  9\n"
     ]
    }
   ],
   "source": [
    "# 方法2\n",
    "wave = pd.DataFrame()\n",
    "c1 = pd.Series(range(0, 5))\n",
    "c2 = pd.Series(range(5, 10))\n",
    "wave['column1'] = c1\n",
    "wave[1] = c2\n",
    "print(wave)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取出指定列数据\n",
    "c1 = pd.Series(range(0, 5))\n",
    "c2 = pd.Series(range(5, 10))\n",
    "df = pd.concat([c1, c2], axis=1)\n",
    "df.rename(columns={0: 'col1', 1: 3}, inplace=True)\n",
    "\n",
    "# 知道列名称的情况下\n",
    "df['col1']\n",
    "df[3]\n",
    "\n",
    "# 不知道列名称，按列的位置取数据\n",
    "col = df.iloc[:, 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Series中，存放的是16进制数据字符串，需要转换成整数\n",
    "s = pd.Series(['003c', '002b'])\n",
    "s_int = s.apply(lambda x: int(x, 16))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
